package com.itheima.day06.myException.test5;

import com.itheima.day01.managerTest.domain.Student;

import java.util.Scanner;

public class Test {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String name;
        int age;
        while (true){
            System.out.println("请输入用户姓名");
            name = sc.next();
            System.out.println("前请输入学生年龄");
            String agestr = sc.next();

            try {
                age = Integer.parseInt(agestr);
                if(age < 18 || age >25){
                    throw new NumberOutOfBoundsException();
                }
            } catch (NumberFormatException e){
                System.out.println("请输入正确数字字符\n");
                continue;
            } catch (NumberOutOfBoundsException e){
                System.out.println("年龄未在范围\n");
                continue;
            }

            System.out.println("创建成功");
            break;
        }

        User u = new User();
        u.setName(name);
        u.setAge(age);
        System.out.println(u.getName() + "---" + u.getAge());

    }
}
